package name.cyh.gulimall.search.thread;

import java.util.concurrent.*;

public class ThreadTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main start");
//        CompletableFuture<Void> 我是计算结果 = CompletableFuture.runAsync(() -> {
//            System.out.println("当前线程：" + Thread.currentThread().getId());
//            System.out.println("我是计算结果");
//        }, service);
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            int i = 1;
            return i;
        }, service);
        Integer integer = future.get();
        System.out.println("main stop......"+integer);
    }



    public static ExecutorService service = Executors.newFixedThreadPool(10);
    public static void Thread(String[] args) throws ExecutionException, InterruptedException {

//        new Thread01().start();
//        Runable01 runable01 = new Runable01();
//        FutureTask<Integer> futureTask = new FutureTask<>(new Callable01());
//        new Thread(futureTask).start();
        /*阻塞等待整个线程完成返回结果*/
//        Integer integer = futureTask.get();

//        service.execute(new Runable01());
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5,
                200,
                10,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(10000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());



    }
    private static class Thread01 extends Thread {
        @Override
        public void run() {
            System.out.println("当前线程："+Thread.currentThread().getId());
            System.out.println("我是计算结果");
        }
    }
    public static class Runable01 implements Runnable{

        @Override
        public void run() {
            System.out.println("当前线程："+Thread.currentThread().getId());
            System.out.println("我是计算结果");
        }
    }
    public static class Callable01 implements Callable<Integer> {

        @Override
        public Integer call() throws Exception {
            System.out.println("当前线程："+Thread.currentThread().getId());
            int i = 1;
            return i;
        }
    }
}
